package com.ricohgag.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ricohgag.entity.RechargeLog;
import com.ricohgag.entity.custom.RechargeLogVo;
import com.ricohgag.service.RechargeLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 肖晖
 * @since 2018-08-25
 */
@Controller
@RequestMapping("/admin/rechargeLog")
public class RechargeLogController {
    @Autowired
    private RechargeLogService rechargeLogService;

    @RequestMapping("/index")
    public ModelAndView toIndex(String username, String startDate, String endDate, @RequestParam(value = "pageNow", defaultValue = "1") Integer current, HttpServletRequest request) throws Exception{
        ModelAndView mav = new ModelAndView("/admin/rechargeLog/index");
        System.out.println("start: "+ startDate+endDate);
        String url = request.getContextPath()+"/admin/rechargeLog/index";

        Page<RechargeLog> page = new Page<>(current, 10);
        List<RechargeLogVo> rechargeLogVos = rechargeLogService.selectRechargeLogPage(username, page, startDate, endDate);

        mav.addObject("name",username);
        mav.addObject("Pager", page);
        mav.addObject("rechargeLogVos",rechargeLogVos);
        mav.addObject("pages", page.getPages());
        mav.addObject("url",url);
        return mav;
    }


}

